package P150;

/**
 * @author LiangMu
 * @version \$Id: P28.java, v 0.1, 2024年07月05日 17:57 LiangMu Exp $$
 */
public class P28 {

    public static int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0;
        int sum = 0;
        int res = 0;
        while (left <= right && right < nums.length) {
            sum += nums[right];
            if (sum >= target) {
                int temp = right - left + 1;
                res = res == 0 ? temp : Math.min(temp, res);
                sum -= nums[left];
                sum -= nums[right];
                ++left;
                continue;
            }
            ++right;
        }
        return res;
    }

    public static void main(String[] args) {
        int[] ints = {2, 3, 1, 2, 4, 3};
        System.out.println(minSubArrayLen(7, ints));
    }

}
